package cn.minhx.types.exception;

import cn.minhx.types.enums.ResponseCode;
import java.io.Serial;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
public class AppException extends RuntimeException {

	@Serial
	private static final long serialVersionUID = 5317680961212299217L;

	/** 异常码 */
	private String code;

	/** 异常信息 */
	private String info;

	public AppException(String code) {
		this.code = code;
	}

	public AppException(String code, Throwable cause) {
		this.code = code;
		super.initCause(cause);
	}

	public AppException(String code, String message) {
		this.code = code;
		this.info = message;
	}

	public AppException(String code, String message, Throwable cause) {
		this.code = code;
		this.info = message;
		super.initCause(cause);
	}

	public AppException(ResponseCode responseCode) {
		this.code = responseCode.getCode();
		this.info = responseCode.getInfo();
	}

	@Override
	public String toString() {
		return "cn.minhx.x.api.types.exception.XApiException{" + "code='" + code + '\'' + ", info='" + info + '\''
				+ '}';
	}
}
